<?php

namespace app\service;

use app\model\WorkPlan;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
use think\facade\Cache;

class Tasks
{

    /**
     * 获取当月每一天记录
     * @param $uid //用户id
     * @param $type //1跟进计划 2任务提醒
     * @param string $ym  //月份
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    //获取当月计划
    public function getMonthPlan($uid, $type, string $ym): array
    {
        $workPlan = new WorkPlan();

        $daysInMonth = date('t',strtotime ($ym));

        $data = [];
        for($i=1;$i<=$daysInMonth;$i++){
            //获取当天开始结束时间

            $start = date('Y-m-d',strtotime ($ym.'-'.$i))." 00:00:00";
            $end = date('Y-m-d',strtotime ($ym.'-'.$i)).' 23:59:59';

            $data[$i]['data'] = $workPlan->getDateBETData($start,$end,$uid,$type);
            $data[$i]['wc'] = $workPlan->getWcDateBETData($start,$end,$uid,$type);//完成
            $data[$i]['wwc'] = $workPlan->getWwcDateBETData($start,$end,$uid,$type);//未完成

        }
        return $data;
    }
    /**
     * 获取当前周内详情
     * @param $uid
     * @param $type
     * @param int $week
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    //获取当前星期计划
    public function getWeekPlan($uid, $type, int $week=7): array
    {
        $workPlan = new WorkPlan();

        $data = [];
        for($i=1;$i<=$week;$i++){
            //获取当天开始结束时间
            $start = date('Y-m-d,H:i:s',strtotime("last Sunday +".$i."days"));
            $end = date('Y-m-d,H:i:s',(strtotime("last Sunday +".($i+1)."days"))-1);

            $data[$i]['data'] = $workPlan->getDateBETData($start,$end,$uid,$type);
            $data[$i]['wc'] = $workPlan->getWcDateBETData($start,$end,$uid,$type);//完成
            $data[$i]['wwc'] = $workPlan->getWwcDateBETData($start,$end,$uid,$type);//未完成

        }
        return $data;
    }

}